package com.hmall.order.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.order.pojo.Order;
import com.hmall.order.pojo.OrderDTO;
import com.hmall.order.pojo.OrderDetail;
import com.hmall.order.pojo.OrderVO;
import com.hmall.order.service.IOrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private IOrderService orderService;

   @GetMapping("{id}")
   public OrderVO queryOrderById(@PathVariable("id") Long orderId) {
      Order order = orderService.getById(orderId);
      OrderVO orderVO = new OrderVO();
      BeanUtils.copyProperties(order,orderVO);
      orderVO.setId(order.getId().toString());
      return orderVO;
   }

   /**
    * 添加订单
    * @param orderDTO
    * @return
    */
   @PostMapping
   public String addOrder(@RequestBody OrderDTO orderDTO){
      return orderService.addOrder(orderDTO).toString();
   }



}
